package com.yc.behavioral.strategy.impl;

import com.yc.behavioral.strategy.CalcStrategy;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 精确乘法计算
 */
public class MulStrategy implements CalcStrategy {
	@Override
	public Double execuCalc(Double num1, Double num2) {
		BigDecimal b1 = new BigDecimal(Double.toString(num1));
		BigDecimal b2 = new BigDecimal(Double.toString(num2));
		// newScale 保留位数
		return b1.multiply(b2).setScale(4, RoundingMode.HALF_UP).doubleValue();
	}
}
